<template>
  <div class="common-layout">
    <el-container>
      <!-- 顶部导航栏 -->
      <el-header class="header">
        <h2>个人博客后台管理系统</h2>
        <div class="header-menu">
          <el-button type="info" @click="logout">退出</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside
          width="200px"
          class="aside"
        >
          <!-- 侧边导航栏 -->
          <el-menu
            class="left-menu"
            :default-active="activePath"
            unique-opened
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409bff"
            router
          >
            <!-- 一级菜单 -->
            <el-submenu :index="item.authName" v-for="(item, i) in menuList" :key="i">
              <template slot="title">
                <span>{{item.authName}}</span>
              </template>
              <!-- 二级菜单 -->
              <el-menu-item v-for="(menu, i) in item.children" :key="i" :index="menu.path">{{menu.authName}}</el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main class="main">
          <!-- Main -->
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
  
  <script>
export default {
  watch: {
    $route(){
      this.activePath = this.$route.path
    },
    activePath: (val) => {
      console.log(val);
    },
  },
  data() {
    return {
      // 当前菜单路径
      activePath: "",
      userinfo: {
        avatar:
          "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
        username: "Admin",
      },
      menuList: [
        {
          authName: "文章管理",
          children: [
            {  authName: "写文章",  path: "/admin/article"},
            {  authName: "文章列表",  path: "/admin/articleList"},
            {  authName: "分类管理",  path: "/admin/category"},
            {  authName: "标签管理",  path: "/admin/tags"},
          ]
        },
        {
          authName: "个人设置",
          children: [{authName: "修改密码",path: "modifyPwd"},
          ]
        },
      ],
    };
  },
  methods: {
    logout() {
      this.$http.post('/logout')
      // 清楚用户验证信息
      window.sessionStorage.clear();
      // 跳转到登录页
      this.$router.push("/login");
    },
  },
};
</script>
  
<style lang="less" scoped>
.common-layout {
  height: 100%;
  background: #fff;
}

.el-container {
  height: 100%;
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #6b798e;
  // background: linear-gradient(135deg,#17ead9,#6078ea);
  padding: 0 50px;
  color: #fff;
}

.aside {

}
.el-main {
  padding: 0 20px;
}
.left-menu {
  min-height: 100%;
}
</style>
    